package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.example.administrator.boltshow.R;

import java.util.List;

import model.SpecialClassifyModel;

/**
 * Created by Administrator on 2016/9/1.
 */
public class SpecialClassifyAdapter extends RecyclerView.Adapter<SpecialClassifyAdapter.ClassifyViewHolder> {
    private boolean flag =false;
    private Context mContext;
    private List<SpecialClassifyModel.DataBean.AttrBean> mData;
    private CompoundButton.OnCheckedChangeListener mListener;
    public SpecialClassifyAdapter(List<SpecialClassifyModel.DataBean.AttrBean> mData, Context mContext, CompoundButton.OnCheckedChangeListener mListener){
        this.mData = mData;
        this.mContext = mContext;
        this.mListener = mListener;

    }
    @Override
    public ClassifyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.special_classify_item,null);
        ClassifyViewHolder holder = new ClassifyViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(ClassifyViewHolder holder, int position) {
        SpecialClassifyModel.DataBean.AttrBean attrBean = mData.get(position);
        holder.cb.setText(attrBean.getTypeName());
        holder.cb.setOnCheckedChangeListener(mListener);
        boolean checkedOne = false;
        if(position == 0) {
            checkedOne = holder.cb.isChecked();
            }
        if(checkedOne) {
            if(position>0) {
                holder.cb.setChecked(false);
            }
        }


    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public static class ClassifyViewHolder extends RecyclerView.ViewHolder{
        private CheckBox cb;
        public ClassifyViewHolder(View itemView) {
            super(itemView);
            cb = (CheckBox) itemView.findViewById(R.id.bt_special_classify_item);
        }
    }
}
